package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantmarginService;
import com.youi.entity.Merchantmargin;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 商家保证金控制层
* @author Administrator
*/
@Controller
public class MerchantmarginController  extends HttpRequestManage{

		@Autowired
		private MerchantmarginService merchantmarginService;

		/**
		 * I-77
		 *添加或编辑商家保证金
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantmargin")
		public String addOrEditMerchantmargin(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantmargin merchantmargin=merchantmarginService.getByParam(prams);
			if (merchantmargin==null) {
				merchantmargin=new Merchantmargin();
				merchantmargin.setDelStatus(DelStatus.NODEL);
				merchantmargin.setGmtCreated(new Date());
				merchantmargin.setMerchantId(id);
			}			
			String signName=optString("signName",request);
			if (signName!=null){
				merchantmargin.setSignName(signName);
			}
			Date gmtContract=optDate("gmtContract", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtContract!=null) {
				merchantmargin.setGmtContract(gmtContract);
			}
			String margin=optString("margin",request);
			if (margin!=null){
				merchantmargin.setMargin(margin);
			}
			Integer isCapture=optInteger("isCapture",request);
			if (isCapture!=null){
				merchantmargin.setIsCapture(isCapture);
			}
			String certificate=optString("certificate",request);
			if (certificate!=null){
				merchantmargin.setCertificate(certificate);
			}
			Date gmtCapture=optDate("gmtCapture", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtCapture!=null) {
				merchantmargin.setGmtCapture(gmtCapture);
			}
			merchantmargin.setGmtModify(new Date());
			merchantmarginService.saveOrUpdate(merchantmargin);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		/**
		 * I-78
		 * 查询商家保证金
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantmarginById")
		public String getMerchantmarginById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantmargin merchantmargin=merchantmarginService.getByParam(prams);
			if (merchantmargin==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantmargin);//jsonObject	json对象
		}

	
}
